<!--
 * @Description: file content
 * @Author: Wenmin He
 * @Date: 2021-07-02 13:40:04
 * @LastEditors: luojie
 * @LastEditTime: 2021-08-08 22:10:19
-->
<template>
	<view class="content">
		<view class='person-info-bg'></view>
		<view class="person-info" @click="goDetail">
			<open-data type="userAvatarUrl" class="person-info-img"></open-data>
			<!-- <view class="person-info-img">
				<image class="person-info-img-src" :src="avatarUrl" mode="widthFix"></image>
			</view> -->
			<view class="person-info-name" >{{personalInfo.name}}</view>
			<view class="record-right" >
				<image class="record-right-img"  src="https://szgd-dev.tgovcloud.com/public/images/arr-right.png" mode="widthFix"></image>
			</view>
		</view>
		<!-- <view class="record" @click="goRecord">
			<view class="record-left" >
				<image class="record-left-img"  src="https://szgd-dev.tgovcloud.com/public/images/icon-scan.png" mode="widthFix"></image>
			</view>
			<view class="record-title" >我的扫码记录</view>
			<view class="record-right" >
				<image class="record-right-img"  src="https://szgd-dev.tgovcloud.com/public/images/arr-right.png" mode="widthFix"></image>
			</view>
		</view> -->
		<view class="my-info">
			<view class="my-info-box" >
				<image class="my-info-box-img"  src="https://szgd-dev.tgovcloud.com/public/images/hs-icon.png" mode="widthFix"></image>
				<view class="my-info-clo" >
					<view class="my-info-tit">核酸检测</view>
					<view class="my-info-txt">{{nucleicAcid || "未检测"}}</view>
					<view class="my-info-timer">{{reportTime || "--"}}</view>
				</view>
			</view>
			<view class="my-info-line" ></view>
			<view class="my-info-box" >
				<image class="my-info-box-img"  src="https://szgd-dev.tgovcloud.com/public/images/xg-icon.png" mode="widthFix"></image>
				<view class="my-info-clo" >
					<view class="my-info-tit">新冠疫苗</view>
					<view class="my-info-txt">{{vaccination?`第${vaccination}针`:'' || "未接种"}}</view>
					<view class="my-info-timer">{{inoculationTime || "--"}}</view>
				</view>
			</view>
		</view>
		<view class="record-list">
			<view class="record" @click="goHealthRecord">
				<view class="record-left" >
					<image class="record-left-img"  src="https://szgd-dev.tgovcloud.com/public/images/icon-record.png" mode="widthFix"></image>
				</view>
				<view class="record-title" >工作记录</view>
				<view class="record-right" >
					<image class="record-right-img"  src="https://szgd-dev.tgovcloud.com/public/images/arr-right.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="record" @click="goHealthReport">
				<view class="record-left" >
					<image class="record-left-img"  src="https://szgd-dev.tgovcloud.com/public/images/icon-report.png" mode="widthFix"></image>
				</view>
				<view class="record-title" >健康填报</view>
				<view class="record-right" >
					<image class="record-right-img"  src="https://szgd-dev.tgovcloud.com/public/images/arr-right.png" mode="widthFix"></image>
				</view>
				<view v-if="reported==0">未上报</view>
				<view v-if="reported==1">已上报</view>
			</view>
			<view class="record" @click="goWorkHelp">
				<view class="record-left" >
					<image class="record-left-img"  src="https://szgd-dev.tgovcloud.com/public/images/referral/work-help.png" mode="widthFix"></image>
				</view>
				<view class="record-title" >业务培训</view>
				<view class="record-right" >
					<image class="record-right-img"  src="https://szgd-dev.tgovcloud.com/public/images/arr-right.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="record face-coll" @click="goFaceColl">
				<view class="record-left" >
					<image class="record-left-img"  src="https://szgd-dev.tgovcloud.com/public/images/referral/face-colle.png" mode="widthFix"></image>
				</view>
				<view class="record-title" >头像采集</view>
				<view class="record-right" >
					<image class="record-right-img"  src="https://szgd-dev.tgovcloud.com/public/images/arr-right.png" mode="widthFix"></image>
				</view>
				<view class="uncompleted txt" v-if="isCollection==0"  >未完成</view>
				<view class="completed txt" v-if="isCollection==1" >已完成</view>
			</view>
		</view>

		<view class="btn-handle">
			<view class="logout-btn" @click="logout">
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
// import func from 'vue-editor-bridge'
import {logout,getGzryInfo, getData, getReportList} from '@/api/index.js'
import { removeAllStorageSync } from '@/utils'
	export default {
		data() {
			return {
				personalInfo:[],
				avatarUrl:'',
				canIUse: wx.canIUse('button.open-type.getUserInfo'),
				nucleicAcid: "",//核酸检测结果
				reportTime: '', //核酸日期
				vaccination: "",//疫苗接种情况
				inoculationTime: "", // 疫苗接种日期
				cardType: '',
				idCard: '',
				reported: -1,	// 是否已上报健康填报
				isCollection: -1,  // 是否头像采集
				faceLastRecord: {},
			}
		},
		onLoad() {
			let personalInfo = uni.getStorageSync('personalInfo');
			this.personalInfo = personalInfo;
			let avatarUrl =uni.getStorageSync('avatarUrl');
			this.getOtherInfo();
			// this.getReported();
			if(avatarUrl !='' && avatarUrl !=undefined){
				this.avatarUrl = avatarUrl;
			}else{
				this.avatarUrl = 'https://szgd-dev.tgovcloud.com/public/images/img-person.png'
			}
			// 查看是否授权
			wx.getSetting({
				success (res){
					if (res.authSetting['scope.userInfo']) {
					// 已经授权，可以直接调用 getUserInfo 获取头像昵称
					wx.getUserInfo({
						success: function(res) {
						uni.setStorage({key:'avatarUrl',data:res.userInfo.avatarUrl})
						}
					})
					}
				}
			})
		},
		methods: {
			goHealthRecord(){
				uni.navigateTo({
					url:'../healthReport/recordList'
				})
			},
			getOtherInfo(){
				getGzryInfo().then((res) => {
					this.nucleicAcid=res.inspectionItemResult;	// 核酸检测结果
					this.reportTime = res.reportTime;	//核酸检测时间
					this.vaccination=res.needleTimes;						// 疫苗针次
					this.inoculationTime = res.inoculationTime;	// 疫苗接种日期
					this.idCard=res.idCard;
					this.cardType=res.cardType;
					this.queryLastRecord(res.idCard);
				});
			},
			goHealthReport(){
				uni.navigateTo({
					url:'../healthReport/list'
				})
			},
			goWorkHelp() {
				uni.navigateTo({
					url:'/packageAlpha/pages/workHelp/list'
				})
			},
			goRecord(){
				uni.navigateTo({
					url:'../scanRecord/index'
				})
			},
			goDetail(){
       			console.log('goDetail')
				uni.navigateTo({
					url:'../myDetail/index'
				})
			},
			logout() {
				logout().then(rs=>{
					removeAllStorageSync();
					uni.reLaunch({
						url:'/pages/index/index',
						success:()=>{
							this.$store.commit('SET_AUTH_STATUS', false)
						}
					})
				})
			},
			goFaceColl(){
				if(this.faceLastRecord.fileUrl){
					uni.setStorageSync('faceLastRecord', {
						fileUrl: this.faceLastRecord.fileUrl
					})
				}
				uni.navigateTo({
					url:`/packageAlpha/pages/faceCollect/index?cardType=${this.cardType}&idCard=${this.idCard}&realName=${this.personalInfo.name}`,
				})
			},
			// 查询工作人员当天是否已完成健康填报
			getReported() {
				console.log('this.pageNum====', this.pageNum);
				const data = {
					pageNum: 1,
					size: 5,
					abnormalSymptoms: '',
				};
				getReportList(data).then((res) => {
					console.log('res===', res);
					if(res.records) {
						this.reported = 1;
					}else{
						this.reported = 0;
					}
				});
			},
			queryLastRecord(identity){
				getData('faceLastRecord', 'get', {identity}).then(data=>{
					if(data&&data.fileUrl){
						this.faceLastRecord={
							fileUrl: data.fileUrl
						};
						this.isCollection=1;
					}else {
						this.isCollection=0;
					}
				})

				// 这个接口会相对快一点
				// getData('faceComplateRecord', 'get', {}).then(data=>{
				// 	console.log(data);
				// 	if(data){
				// 		this.faceLastRecord={
				// 			fileUrl: data.fileUrl
				// 		};
				// 		this.isCollection=1;
				// 	}else {
				// 		this.isCollection=0;
				// 	}
				// })
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width:100%;
		height: 100vh;
		box-sizing: border-box;
		background-color: #f9f9f9;
	}
	.person-info-bg{
		background: #1394F5;
    height: 81rpx;
    width: 100%;
    position: absolute;
	}
	.person-info{
		width: 100%;
		background-color: #fff;
		height: 200rpx;
		line-height: 200rpx;
		padding-left:40rpx;
		padding-right: 40rpx;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		position:relative;
		&-img{
			width: 120rpx;
			height: 120rpx;
			overflow: hidden;
			border-radius: 120rpx;
			display: inline-block;
			vertical-align: middle;
			margin-right:40rpx;
			&-src{
				width:100%;
			}
		}
		&-name{
			font-weight: 600;
			font-size: 40rpx;
			vertical-align: middle;
		}
	}
	.record-list{
		margin-top:30rpx;
	}
	.record{
		background-color: #fff;
		text-align: center;
		padding:20rpx;
		padding-left: 43rpx;
		line-height: 80rpx;
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #D0D0D0;
		&-title{
			padding:0 20rpx;
		}
		&-right{
			flex: 1;
			line-height: 80rpx;
			text-align: right;
			&-img{
				width:20rpx;
			}
		}
		&-left{
			padding-top:12rpx;
			&-img{
				width:40rpx;
				height:40rpx;
			}
		}
	}
	.no-border{
		border-bottom: none;
	}
	.btn-handle {
		padding: 70rpx 30rpx 50rpx;
	}
	.logout-btn{
		text-align: center;
		line-height: 100rpx;
		background-color: #fff;
		border:1px solid #D0D0D0;
		border-radius: 16rpx;
		font-size:34rpx;
	}
	.my-info{
		margin-top:30rpx;
		background-color: #fff;
		text-align: center;
		padding:20rpx;
		line-height: 238rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 54rpx;
		padding-right: 54rpx;
		&-line{
			width: 0px;
			height: 156rpx;
			border: 1rpx solid #D0D0D0;
			opacity: 1;
		}
		&-right{
			flex: 1;
			line-height: 80rpx;
			text-align: right;
			&-img{
				width:98rpx;
			}
		}
		&-left{
			padding-top:12rpx;
			&-img{
				width:98rpx;
			}
		}
		&-box{
			display: flex;
			justify-content: center;
			align-items: center;
			&-img{
				margin-right:26rpx;
				width:98rpx;
				height: 98rpx;
			}
		}
		&-clo{
			width: 150rpx;
			height: 140rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

		}
		&-tit{
		width: 120rpx;
		height: 30rpx;
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		line-height: 27rpx;
		color: #666666;
		opacity: 1;
		text-align: center;
		margin:0 auto;
		}
		&-txt{
		width: 120rpx;
		font-size: 40rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		line-height: 27rpx;
		color: #66DD55;
		opacity: 1;
		text-align: center;
		margin:0 auto;
		}
		&-timer{
			font-size:26rpx;
			color:#666666;
			line-height:26rpx;
			margin:0 auto;
		}
	}
	.face-coll {
		position: relative;
		overflow: hidden;
		& > .txt { 
			width: 90px;
			height: 42rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			line-height: 42rpx;
			opacity: 1;
			position: absolute;
			right: 1em;
			transform: translateY(-6rpx);
		}
		.uncompleted {
			color: #F15B53;
		}
		.completed {
color: #62E250;
		}
	}
</style>>
